package servlet;

import model.Interaction;
import service.InteractionService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
//管理员对消息互动管理的请求
@WebServlet(name = "AdminInteractionManagementServlet", urlPatterns = "/admin/interaction_management")
public class AdminInteractionManagementServlet extends HttpServlet {
    private InteractionService interactionService = new InteractionService();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 验证用户是否为管理员
        // 这里可以添加权限验证逻辑，如检查 session 中的用户信息是否为管理员

        // 获取所有互动记录
        List<Interaction> interactionList = interactionService.getAllInteractions();

        // 将互动记录存入 request 作用域
        request.setAttribute("interactionList", interactionList);

        // 转发到管理员消息互动管理页面
        request.getRequestDispatcher("/admin/interaction_management.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}